let itemDouYin = className("android.widget.LinearLayout").depth("23").drawingOrder("1").find()
itemDouYin = itemDouYin.filter(e=>e.child(0).child(1).childCount()>=2)
click(itemDouYin[0].child(1).child(0).child(1).bounds().centerX(),itemDouYin[0].child(1).child(0).child(1).bounds().centerY())
sleep(random(2000,3000))
findKeyword()
function findKeyword () {
    const guangGaoDY = className("android.widget.TextView").depth("24").drawingOrder("1").text('广告').findOne(2000)
    if(!guangGaoDY){
      const keywordNameDY = className("android.widget.TextView").depth('22').drawingOrder('3').desc('按钮').findOne(2000) 
      const keywordDayDY = className("android.widget.TextView").depth('26').drawingOrder('1').findOne(2000) 
      const keywordTitle = className("android.widget.TextView").depth("24").desc('按钮').drawingOrder("1").findOne(2000)
      console.log(keywordNameDY.text());
      console.log(keywordDayDY.text());
      console.log(keywordTitle.text());
      const pingLun = className("android.widget.LinearLayout").depth('21').drawingOrder('1').find()
      if(pingLun[1]){
          if(pingLun[1].child(1).child(0).text()=="评论"){
              toast('没有评论')
              swipe(
                  device.width / 2,
                  device.height * 0.8,
                  device.width / 2,
                  device.height * 0.2,
                  random(500,1000)
              )
              findKeyword()
          }else{
              pingLun[1].click()
              jieLiuKeyword()
              sleep(random(1000,2000))
              swipe(
                device.width / 2,
                device.height * 0.8,
                device.width / 2,
                device.height * 0.2,
                random(500,1000)
              )
              findKeyword()
          }
      }
    }
    swipe(
      device.width / 2,
      device.height * 0.8,
      device.width / 2,
      0,
      random(500,1000)
    )
    sleep(random(1000,2000))
    findKeyword()
}
function jieLiuKeyword(){
  sleep(random(2000,3000))
  const list = className("android.widget.TextView").depth("15").drawingOrder("27").find()
  const arr = []
  list.forEach(e=>{
      arr.push(e.parent().child(1).bounds().height())
  })
  list.forEach(e=>{
      // 筛选掉最后一个
      sleep(random(2000,3000))
      if(e.parent().child(1).bounds().height() < findMax(arr)) return
      // 评论
      console.log(e.parent().child(2).text());
      console.log(e.parent().child(4).child(1).text());
      console.log(e.text());
      click(e.parent().child(1).bounds().centerX(), e.parent().child(1).bounds().centerY())
      sleep(random(2000,3000))
      const DouYinHao = className("android.widget.TextView").depth("12").drawingOrder("2").findOne(2000)
      let IPDouYin = className("android.widget.TextView").depth("12").find()
      IPDouYin = IPDouYin.filter(e=>e.text().includes('IP'))
      if(DouYinHao&&IPDouYin.length){
        console.log(DouYinHao.text());
        console.log(IPDouYin[0].text()); 
      }
      back()
      sleep(random(1000,3000))
  })
  if(className("android.widget.TextView").depth("14").drawingOrder("2").text("暂时没有更多了").findOne(2000)){
      toast('没有评论了')
      back()
  }else{
      const PingLunBox = className("android.widget.FrameLayout").depth("6").drawingOrder("2").findOne(2000)
      swipe(
        device.width / 2,
        device.height * 0.8,
        device.width / 2,
        device.height * 0.2,
        random(1000,2000)
      )
      jieLiuKeyword()
  }
}

function findMax(array) {
  let max = array[0];
  for (let i = 1; i < array.length; i++) {
      if (array[i] > max) {
          max = array[i];
      }
  }
  return max;
}